package service

import (
	"context"
	__ "goods_srv/basic/goodsrpc"
	"goods_srv/handler/dao"
)

// 添加快递柜
func (s *Server) CreateCabinet(ctx context.Context, in *__.CreateCabinetReq) (*__.CreateCabinetResp, error) {
	id, err := dao.CreateCabinet(in)
	if err != nil {
		return nil, err
	}
	return &__.CreateCabinetResp{
		Id: id,
	}, nil
}

// 修改快递柜
func (s *Server) UpdateCabinet(ctx context.Context, in *__.UpdateCabinetReq) (*__.UpdateCabinetResp, error) {
	res, err := dao.UpdateCabinet(in)
	if err != nil {
		return nil, err
	}
	return &__.UpdateCabinetResp{
		Res: res,
	}, nil
}

// 快递柜详情
func (s *Server) CabinetDetail(ctx context.Context, in *__.CabinetDetailReq) (*__.CabinetDetailResp, error) {
	res, err := dao.CabinetDetail(in.Id)
	if err != nil {
		return nil, err
	}
	return &__.CabinetDetailResp{
		Id:               res.Id,
		CabinetNo:        res.CabinetNo,
		ChargingStandard: res.ChargingStandard,
		AddressId:        res.AddressId,
		SizeId:           res.SizeId,
		Hot:              res.Hot,
		Status:           int32(res.Status),
	}, nil
}

// 位置展示
func (s *Server) CabinetLocation(ctx context.Context, in *__.CabinetLocationReq) (*__.CabinetLocationResp, error) {
	res, err := dao.CabinetLocation()
	if err != nil {
		return nil, err
	}
	return &__.CabinetLocationResp{
		List: res,
	}, nil
}

// 位置展示
func (s *Server) GetCabinetBySize(ctx context.Context, in *__.GetCabinetBySizeReq) (*__.GetCabinetBySizeResp, error) {
	list, err := dao.GetCabinetBySize(in)
	if err != nil {
		return nil, err
	}
	return &__.GetCabinetBySizeResp{
		List: list,
	}, nil
}
